package com.ckd.flyingtrip.adapter;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ckd.flyingtrip.R;
import com.ckd.flyingtrip.activity.BaseActivity;
import com.ckd.flyingtrip.activity.GoumaiActivity;
import com.ckd.flyingtrip.javabean.MaiCheBean;
import com.ckd.flyingtrip.utils.Tools;

import java.util.List;


/**
 * Created by HITMAN on 2017/9/6 0006.
 */
public class GridViewMaicheiAdapter extends BaseAdapter {
    private List<MaiCheBean> list;
    LayoutInflater layoutInflater;
    private BaseActivity context;
    public GridViewMaicheiAdapter(BaseActivity context, List<MaiCheBean> list) {
        this.context = context;
        this.list = list;
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressLint("ViewHolder")
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        View view = null;
        if (convertView == null) {
            view = View.inflate(context, R.layout.item_fankuiimg, null);
            holder = new ViewHolder();
            view.setTag(holder);
            holder.txt_name =  view.findViewById(R.id.txt_name);
            holder.txt_money =  view.findViewById(R.id.txt_money);
            holder.txt_shengyu =  view.findViewById(R.id.txt_shengyu);
            holder.img =  view.findViewById(R.id.img);
        } else {
            view = convertView;
            holder = (ViewHolder) convertView.getTag();
        }
        MaiCheBean maiCheBean = list.get(position);
        holder.txt_name.setText(maiCheBean.getBicycleName());
        holder.txt_money.setText("价格："+maiCheBean.getBicyclePrice());
        holder.txt_shengyu.setText("剩余"+maiCheBean.getBicycleSurplus()+"辆");
        Tools.loadImg(maiCheBean.getBicyclePictureUrl(),holder.img);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent inten = new Intent(context, GoumaiActivity.class);
                inten.putExtra("id",maiCheBean.getBicycleId());
                context.startActivity(inten);
            }
        });
        return view;
    }


    static class ViewHolder {
        TextView txt_name,txt_money,txt_shengyu;
        ImageView img;

    }
}